package com.example.j20240317.demos.web.model;

import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String errmsg;
    private T data;

    public static<T> Result<T> success(T data){
        Result result = new Result<T>();
        result.setData(data);
        result.setCode(200);
        return result;
    }
    public static<T> Result<T> fail(T data,String errMsg){
        Result result = new Result<T>();
        result.setData(data);
        result.setCode(-1);
        result.setErrmsg(errMsg);
        return result;
    }
    public static<T> Result<T> fail(String errMsg){
        Result result = new Result<T>();
        result.setCode(-1);
        result.setErrmsg(errMsg);
        return result;
    }

    public static<T> Result unLogin(){
        Result result = new Result<T>();

        result.setCode(-2);
        result.setErrmsg("用户未登录");
        return result;
    }
}
